<template>
	<view class="cart">
		<view class="cart_de">
			<text class="type">车牌</text>
			<view class="plateNo">
				<up-input
				 border="surround"
				  v-model="cardate.plateNo"
				 ></up-input>
			</view>
			 
		</view>
		<view class="cart_de">
			<text class="type">车类型</text>
			<view class="plateNo">
			<up-input
			 border="surround"
			  v-model="cardate.type"
			 ></up-input>
			 </view>
		</view>
		
		<view class="same">
			 <up-button type="primary" text="修改" @click="makecart"></up-button>
		</view>
		<view class="same">
			 <up-button type="error" text="删除" @click="delecart"></up-button>
		</view>
		
	</view>
</template>

<script setup>
import { getCurrentInstance, onMounted, ref } from 'vue';
import {fixmycart,deletecart} from '@/api/parkApi.js'
import {onLoad} from '@dcloudio/uni-app'

const cardate=ref({})  //车辆详情

//删除车辆信息
const delecart=async()=>{
	let res = await deletecart({
		id:cardate.value.id,
		header:{
		 'Authorization':uni.getStorageSync('token')
		}
	})
	if(res.code==200){
	uni.showToast({
		title:'删除成功'
	})
	uni.navigateTo({
		url:'/pages/park/cart/mycart/mycart'
	})	
	}else{
		//静态数据
	uni.showToast({
		title:'删除成功'
	})
	uni.navigateTo({
		url:'/pages/park/cart/mycart/mycart'
	})	
		
	}
}

//修改车辆信息
const makecart=async()=>{

	let res = await fixmycart({
		header:{
		 'Authorization':uni.getStorageSync('token')
		},
		data:{
			id:cardate.value.id,
			plateNo:cardate.value.plateNo,
			type:cardate.value.type
		}
	})
	if(res.code==200){
		uni.showToast({
			title:'修改成功'
		})
		uni.navigateTo({
			url:'/pages/park/cart/mycart/mycart'
		})
	}else{
		//静态数据
		uni.showToast({
			title:'修改成功'
		})
		uni.navigateTo({
			url:'/pages/park/cart/mycart/mycart'
		})
		
	}

}

//获取车辆详细信息
const getcardate=()=>{
	// let date=getCurrentInstance().attrs.park
	// cardate.value=JSON.parse(date)
}

onLoad((option)=>{
	let date=option.park
	cardate.value=JSON.parse(date)
})

// onMounted(()=>{
// 	getcardate()
	
// })
</script>
<style lang="scss">
.cart{
  padding: 4px 10px;
  .cart_de{
	  display: flex;
	  align-items: center;
	  padding: 6px;
	  margin-bottom: 10px;
	  
	  .type{
		  flex: 1;
		  font-size: 18px;
		  font-weight: 700;
	  }
	  .plateNo{
		  flex: 4;
	  }
	 
  }
  .same{
  		  margin: 14px 0px;
  }
}
</style>
